package com.lzyyj.gmis.base.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FieldTree extends Field {
	
	private int colSpan = 1;
	
	private int rowSpan = 1;
	
	private int charLength;
	
	private int charHeight;
	
	private int depth;
	
	private FieldTree parent;
	
	private Map<String, List<FieldTree>> fieldMap = new HashMap<String, List<FieldTree>>();
	
	public Map<String, List<FieldTree>> getFieldMap() {
		return fieldMap;
	}

	public void setFieldMap(Map<String, List<FieldTree>> fieldMap) {
		this.fieldMap = fieldMap;
	}

	private List<FieldTree> subTitleList = new ArrayList<FieldTree>();

	public int getColSpan() {
		return colSpan;
	}

	public void setColSpan(int colSpan) {
		this.colSpan = colSpan;
	}

	public int getRowSpan() {
		return rowSpan;
	}

	public void setRowSpan(int rowSpan) {
		this.rowSpan = rowSpan;
	}

	public int getCharLength() {
		return charLength;
	}

	public void setCharLength(int charLength) {
		this.charLength = charLength;
	}

	public int getCharHeight() {
		return charHeight;
	}

	public void setCharHeight(int charHeight) {
		this.charHeight = charHeight;
	}

	public int getDepth() {
		return depth;
	}

	public void setDepth(int depth) {
		this.depth = depth;
	}

	public FieldTree getParent() {
		return parent;
	}

	public void setParent(FieldTree parent) {
		this.parent = parent;
	}

	public List<FieldTree> getSubTitleList() {
		return subTitleList;
	}

	public void setSubTitleList(List<FieldTree> subTitleList) {
		this.subTitleList = subTitleList;
	}

	/**
	 * 添加标题列表
	 * @param string
	 */
	public void addTitleList(String titleList) {
		if(titleList!=null&&titleList.length()>0) {
			String[] titleLevels = titleList.split(":");
			String titleListString = titleLevels[titleLevels.length-1];
			FieldTree parent = null;
			for(int i=0;i<depth-1;i++) {
				int parentLevel = titleLevels.length-1-i;
				if(parentLevel>=0&&parentLevel<titleLevels.length-1) {
					String parentTitle = titleLevels[parentLevel];
					parent = new FieldTree();
					parent.setName(parentTitle);
					parent.setSubTitleList(new ArrayList<FieldTree>());
					parent.setColNum(subTitleList.size());
				}
			}

			for(String title:titleListString.split(";")) {
				if(title.length()>0) {
					if(subTitleList==null) {
						subTitleList = new ArrayList<FieldTree>();
					}
					FieldTree subTitle = new FieldTree();
					subTitle.setName(title);
					subTitle.setParent(parent);
					if(parent!=null) {
						parent.getSubTitleList().add(subTitle);
						parent.setColSpan(parent.getSubTitleList().size());
					}
					subTitleList.add(subTitle);
				}
			}
		}
	}

	public void addField(FieldTree field, String titleName) {
		List<FieldTree> list = fieldMap.get(titleName);
		if(list==null) {
			list = new ArrayList<FieldTree>();
			fieldMap.put(titleName, list);
		}
		list.add(field);
		subTitleList.add(field);
	}

}
